package types

import (
	bytes "bytes"
	database_sql_driver "database/sql/driver"
	errors "errors"

	github_com_go_courier_enumeration "github.com/go-courier/enumeration"
)

var InvalidAdditionalType = errors.New("invalid AdditionalType type")

func ParseAdditionalTypeFromLabelString(s string) (AdditionalType, error) {
	switch s {
	case "":
		return ADDITIONAL_TYPE_UNKNOWN, nil
	case "项目ID":
		return ADDITIONAL_TYPE__PROJECT_ID, nil
	case "RTSP":
		return ADDITIONAL_TYPE__RTSP, nil
	}
	return ADDITIONAL_TYPE_UNKNOWN, InvalidAdditionalType
}

func (v AdditionalType) String() string {
	switch v {
	case ADDITIONAL_TYPE_UNKNOWN:
		return ""
	case ADDITIONAL_TYPE__PROJECT_ID:
		return "PROJECT_ID"
	case ADDITIONAL_TYPE__RTSP:
		return "RTSP"
	}
	return "UNKNOWN"
}

func ParseAdditionalTypeFromString(s string) (AdditionalType, error) {
	switch s {
	case "":
		return ADDITIONAL_TYPE_UNKNOWN, nil
	case "PROJECT_ID":
		return ADDITIONAL_TYPE__PROJECT_ID, nil
	case "RTSP":
		return ADDITIONAL_TYPE__RTSP, nil
	}
	return ADDITIONAL_TYPE_UNKNOWN, InvalidAdditionalType
}

func (v AdditionalType) Label() string {
	switch v {
	case ADDITIONAL_TYPE_UNKNOWN:
		return ""
	case ADDITIONAL_TYPE__PROJECT_ID:
		return "项目ID"
	case ADDITIONAL_TYPE__RTSP:
		return "RTSP"
	}
	return "UNKNOWN"
}

func (v AdditionalType) Int() int {
	return int(v)
}

func (AdditionalType) TypeName() string {
	return "demo/device-hub/constants/types.AdditionalType"
}

func (AdditionalType) ConstValues() []github_com_go_courier_enumeration.IntStringerEnum {
	return []github_com_go_courier_enumeration.IntStringerEnum{ADDITIONAL_TYPE__PROJECT_ID, ADDITIONAL_TYPE__RTSP}
}

func (v AdditionalType) MarshalText() ([]byte, error) {
	str := v.String()
	if str == "UNKNOWN" {
		return nil, InvalidAdditionalType
	}
	return []byte(str), nil
}

func (v *AdditionalType) UnmarshalText(data []byte) (err error) {
	*v, err = ParseAdditionalTypeFromString(string(bytes.ToUpper(data)))
	return
}

func (v AdditionalType) Value() (database_sql_driver.Value, error) {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}
	return int64(v) + int64(offset), nil
}

func (v *AdditionalType) Scan(src interface{}) error {
	offset := 0
	if o, ok := (interface{})(v).(github_com_go_courier_enumeration.DriverValueOffset); ok {
		offset = o.Offset()
	}

	i, err := github_com_go_courier_enumeration.ScanIntEnumStringer(src, offset)
	if err != nil {
		return err
	}
	*v = AdditionalType(i)
	return nil
}
